package com.clstu.homeworks;

import java.util.ArrayList;
import java.util.List;

public class HomeWork01 {
    public static void main(String[] args) {
        News news=new News("新冠确诊病例超千万，许多的大帅哥陈龙为了解决新冠作出重要决定，立即出手。");
        News news1=new News("男子突然想起两个月前掉到的鱼还在兜里，捞起来一看感觉放生");
        List list=new ArrayList();
        list.add(news);
        list.add(news1);
        for (int i = 0; i < 2; i++) {
            News n=(News) list.get(i);
            String s = n.getTitle();
            System.out.println(processTitle(s));
//            if (s.length()>=15){//要记得有一个subString()方法
//                char[] cs=s.toCharArray();
//                for (int j = 0; j < 15; j++) {
//                    System.out.print(cs[j]);
//                }
//                System.out.println("...");
//            }else {
//                System.out.println(s);
//            }
        }
    }
    public static String processTitle(String s){//substring() !!!!!!
        if (s.length()>15){
            return s.substring(0,15)+"...";//返回[0，15)
        }else return s;
    }
}
class News{
    private String title;
    private String article;

    public News(String title) {
        this.title = title;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getArticle() {
        return article;
    }

    public void setArticle(String article) {
        this.article = article;
    }

    @Override
    public String toString() {
        return  title;
    }
}